export default {
    setShopData(s,data){
        s.data=[]
        s.data = data
        // for(let d of data){
        //     for(let i of d.orderLists){
        //         i.checked = false
        //         i.much = i.count
        //         i.id = i.goodsId
        //     }
        //     s.data.push({
        //         ...d.store,
        //         checked:false,
        //         data:[...d.orderLists]
        //     })
        // }
    },
    checkShopItem(s, data) {
        for (let f in s.data) {
            if (s.data[f].id == data.fid) {
                for (let i in s.data[f].data) {
                    if (s.data[f].data[i].id == data.id) {
                        let d = s.data[f].data[i]
                        d.checked = data.b
                        if (!data.b) {
                            s.isCheckAll = false
                        }
                        break;
                    }
                }
                break;
            }
        }
        uni.setStorageSync('shop',s.data)
    },
    setShopMuch(s, data = { id: "", fid: "", much: 0 }) {
        for (let f in s.data) {
            if (s.data[f].id == data.fid) {
                for (let i in s.data[f].data) {
                    if (s.data[f].data[i].id == data.id) {
                        let d = s.data[f].data[i]
                        if (data.much >= 1) {
                            d.much = data.much
                        }
                        break;
                    }
                }
                break;
            }
        }
        uni.setStorageSync('shop',s.data)
    },
    checkItemAll(s, data) {
        for (let f in s.data) {
            if (s.data[f].id == data.id) {
                s.data[f].checked = data.b
                for (let i in s.data[f].data) {
                    let d = s.data[f].data[i]
                    d.checked = data.b
                    if (!data.b) {
                        s.isCheckAll = data.b
                    }
                }
            }
        }
        uni.setStorageSync('shop',s.data)
    },
    checkShopAll(s, b) {
        s.isCheckAll = b
        for (let f in s.data) {
            s.data[f].checked = b
            for (let i in s.data[f].data) {
                let d = s.data[f].data[i]
                d.checked = b
            }
        }
        uni.setStorageSync('shop',s.data)
    },
    delItem(s, d) {
        for (let f in s.data) {
            if (s.data[f].id == d) {
                s.data.splice(f, 1)
                break
            } else {
                for (let i in s.data[f].data) {
                    if (s.data[f].data[i].id == d) {
                        s.data[f].data.splice(i, 1)
                        if (s.data[f].data.length == 0) {
                            s.data.splice(f, 1)
                        }
                        break
                    }
                }
            }
        }
        uni.setStorageSync('shop',s.data)
    },
    addItem(s, d) {
        console.log(d);
        for (let f in s.data) {
            if (s.data[f].id == d.id) {
                for (let i in s.data[f].data) {
                    if (s.data[f].data[i].id == d.data[0].id) {
                        s.data[f].data[i].much = d.data[0].much + s.data[f].data[i].much
                        s.data[f].data[i].checked = true
                        uni.setStorageSync('shop',s.data)
                        return
                    }
                }
                d.data[0].checked = true
                s.data[f].data.push(d.data[0])
                uni.setStorageSync('shop',s.data)
                return
            }
        }
        d.checked = false
        d.data[0].checked = true
        s.data.push(d)
        uni.setStorageSync('shop',s.data)
    }
}
